import request from "@/utils/request"

// 查询巡检日期记录列表
export function listDateRecord(query) {
  return request({
    url: "/ldzl-sb/inspection/date-record/list",
    method: "get",
    params: query
  })
}

// 查询巡检日期记录详细
export function getDateRecord(recordId) {
  return request({
    url: "/ldzl-sb/inspection/date-record/" + recordId,
    method: "get"
  })
}

// 根据巡检单ID获取巡检日期记录列表
export function getByInspectionRecord(inspectionRecordId) {
  return request({
    url: "/ldzl-sb/inspection/date-record/by-record/" + inspectionRecordId,
    method: "get"
  })
}

// 根据巡检单ID和日期获取巡检日期记录
export function getByDate(inspectionRecordId, inspectionDate) {
  return request({
    url: "/ldzl-sb/inspection/date-record/by-date",
    method: "get",
    params: {
      inspectionRecordId,
      inspectionDate
    }
  })
}

// 新增巡检日期记录
export function addDateRecord(data) {
  return request({
    url: "/ldzl-sb/inspection/date-record",
    method: "post",
    data: data
  })
}

// 修改巡检日期记录
export function updateDateRecord(data) {
  return request({
    url: "/ldzl-sb/inspection/date-record",
    method: "put",
    data: data
  })
}

// 删除巡检日期记录
export function delDateRecord(recordId) {
  return request({
    url: "/ldzl-sb/inspection/date-record/" + recordId,
    method: "delete"
  })
}

// 初始化巡检单的巡检日期记录
export function init(inspectionRecordId) {
  return request({
    url: "/ldzl-sb/inspection/date-record/init/" + inspectionRecordId,
    method: "post"
  })
}

// 保存巡检日期结果
export function saveResult(data) {
  console.log("发送保存巡检日期结果API请求，数据:", data);
  return request({
    url: "/ldzl-sb/inspection/date-record/save-result",
    method: "post",
    data: data
  }).then(response => {
    console.log("保存巡检日期结果API响应:", response);
    return response;
  }).catch(error => {
    console.error("保存巡检日期结果API错误:", error);
    throw error;
  });
}

// 检查巡检单是否已完成所有日期的巡检
export function checkCompleted(inspectionRecordId) {
  return request({
    url: "/ldzl-sb/inspection/date-record/check-completed/" + inspectionRecordId,
    method: "get"
  })
}
